﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection.Emit;
using System.Text;
using System.Windows.Forms;

namespace 加密程序
{
    public partial class Form1 : Form
    {
        private List<JsonValue> json;

        private TextBox textBox1;

        private Button button1;

        public Form1()
        {
            InitializeComponent();

            try
            {
                if (File.Exists("000"))
                {
                    label2.Text = File.ReadAllText("000");
                }
                else
                {
                    string contents = Guid.NewGuid().ToString();
                    label2.Text = contents;
                    File.WriteAllText("000", contents);
                }


                if (File.Exists("ex.IOY") && Coop.AuthInitail())
                {
                    string text = File.ReadAllText("ex.IOY", Encoding.UTF8);
                    json = JsonConvert.DeserializeObject<List<JsonValue>>(text);
                    if (Coop.GetTime())
                    {
                        Start();
                    }
                }
            }
            catch (Exception ex)
            {
                File.WriteAllText("1.txt",ex.Message);
            }
          
        }


        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (Coop.GetTime())
                {
                    Start();
                }
                else
                {
                    JsonValue jsonValue = json.Find((x) => x.Password == textBox1.Text);
                    if (jsonValue is null)
                    {
                        return;
                    }
                    Coop.InitialTime(jsonValue.ChooseTime);
                    if (Coop.GetTime())
                    {
                        Start();
                    }
                }
            }
            catch (Exception ex)
            {
                File.WriteAllText("2.txt",ex.Message);
            }
          
        }

        public void Start()
        {
            try
            {
                Process.Start(json[0].AppName);
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                File.WriteAllText("3.txt", ex.Message);
            }
        }

    }
}
